package team.paimengshop.server_socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerManage
{
    private static int clientNumber;
    private ServerSocket serverSocket;

    public static void setClientNumber(int clientNumber)
    {
        ServerManage.clientNumber = clientNumber;
    }

    public static int getClientNumber()
    {
        return clientNumber;
    }

    public ServerManage()
    {

    }

    public ServerManage(ServerSocket serverSocket)
    {
        this.serverSocket = serverSocket;
        clientNumber = 0;
    }

    public void Connect()
    {
        try
        {
            while(true)
            {
                Socket socket = serverSocket.accept();
                new Thread(new ThreadControl(socket)).start();
                ServerManage.setClientNumber(ServerManage.getClientNumber() + 1);
                System.out.println("有新的客户端连接");
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
